package com.example.blogserver.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.util.ResourceUtils;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


import java.io.File;
import java.io.FileNotFoundException;


@SuppressWarnings({"all"})
@Configuration
public class MyWebMvcConfig implements WebMvcConfigurer {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        File path = null;
        try {
            path = new File(ResourceUtils.getURL("classpath:").getPath());
        }catch (FileNotFoundException e){
            e.printStackTrace();
        }
        String gitPath = path.getParentFile().getParentFile().getParent() + File.separator + "photo" + File.separator;
        registry.addResourceHandler("/photo/**").addResourceLocations(gitPath);
        WebMvcConfigurer.super.addResourceHandlers(registry);
    }
}
